package com.example.demo.controller;

import com.example.demo.annotation.UserLoginToken;
import com.example.demo.entity.TbTagEntity;
import com.example.demo.service.TbTagService;
import com.example.demo.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api("后台标签API")
@RestController
@RequestMapping("/admin/tag")
public class AdminTagController {
    TbTagService tbTagService;

    @Autowired
    void setTbTagService(TbTagService tbTagService) {
        this.tbTagService = tbTagService;
    }

    @ApiOperation("获取全部标签")
    @GetMapping("getAllTag")
    public Result getAllTag() {
        return new Result(0, "success", tbTagService.getAllTag());
    }

    @UserLoginToken
    @ApiOperation("添加标签")
    @PostMapping("saveTag")
    public Result saveTag(@RequestBody TbTagEntity tagEntity) {
        return new Result(0, "success", tbTagService.saveTag(tagEntity));
    }

    @UserLoginToken
    @ApiOperation("删除标签")
    @PostMapping("deleteTagById")
    public Result deleteTagById(@RequestBody TbTagEntity tagEntity) {
        if(tagEntity == null || tagEntity.getTagId() == null) {
            return new Result(1, "参数错误");
        }
        tbTagService.deleteTagById(tagEntity.getTagId());
        return new Result(0, "success");
    }
}
